import Vue from 'vue'
import Vuex from 'vuex'
import request from '../assets/utils/request'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 搜索记录
    searchVal: '',
    // 购车价格结算
    shoppingPrice: 0,
    shoppingList: [],
    // 首页列表
    homeList: [],
    isOverlay: false,
    // 头像
    head_img: 'http://r7ij7rcyr.hn-bkt.clouddn.com/QQ%E5%9B%BE%E7%89%8720220222133817.jpg'
  },
  mutations: {
    listTowChange (state, val) {
      state.searchVal = val
      console.log(state.searchVal)
    },
    homeList (state, val) {
      state.homeList = val
    },
    overlayChanged (state, val) {
      state.isOverlay = val
    },
    head_imgChanged (state, val) {
      state.head_img = val
      console.log(val, 111111111111111111)
    }
  },
  actions: {
    getHomeList (store) {
      return new Promise((resolve, reject) => {
        request.get('/api/search/list2')
          .then((res) => {
            store.commit('homeList', res)
            resolve(res)
          })
      })
      // request.get('/api/search/list2').then((data) => {

      //   console.log(data)
      // })
    }
  },
  modules: {
  }
})
